package ru.gelin.android.bells;

import java.util.Date;

import android.app.Activity;
import android.os.Bundle;

/**
 *  Activity which tracks (saves into instance state) the time
 *  when it is started.
 */
public class NowActivity extends Activity {

    /** Key in the instance state bundle to save activity start time */
    static final String NOW_KEY = "now";
    
    /** Current time (when activity is started) */
    Date now;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (savedInstanceState == null) {   //first start
            now = new Date();
        } else {    //restart
            now = new Date(
                    savedInstanceState.getLong(NOW_KEY, System.currentTimeMillis()));
        }
    }
    
    @Override
    protected void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        outState.putLong(NOW_KEY, now.getTime());
    }

}